<?php
!defined('IN_HDWIKI') && exit('Access Denied');

class control extends base{

	function control(& $get,& $post){
		$this->base( & $get,& $post);
		$this->load('setting');
		$this->load('doc');
		$this->view->setlang($this->setting['lang_name'],'back');
	}

	/*recommend doc*/
	function dofocuslist(){
		$page = max(1, intval($this->get[2]));
		$num = isset($this->setting['list_prepage'])?$this->setting['list_prepage']:20;
		$start_limit = ($page - 1) * $num;
		$count=$_ENV['doc']->get_focus_total_num();
		
		$lists=$_ENV['doc']->get_focus_list($start_limit,$num);
		$departstr=$this->multi($count, $num, $page,'admin_focus-focuslist');
		$this->view->assign('lists',$lists);
		$this->view->assign("departstr",$departstr);
		$this->view->display("admin_focus");
	}

	/*remove recommend doc*/
	function doremove(){
		$did=isset($this->post['did'])?$this->post['did']:'';
		if(is_array($did)){
			if($_ENV['doc']->remove_focus($did)){
				$this->cache->removecache('indexcache');
				$this->message($this->view->lang['docRemoveFocusSuccess'],'index.php?admin_focus-focuslist');
			}else{
				$this->message($this->view->lang['docRemoveFocusFail'],'index.php?admin_focus-focuslist');
			}
		}else{
			$this->message($this->view->lang['docRemoveDocNull']);
		}
	}

	/*doc order*/
	function doreorder(){
		$all_focus_did=$this->post['all_focus_did'];
		$count=count($all_focus_did);
		for($i=0;$i<$count;$i++){
			$focusorder='order'.$all_focus_did[$i];
			$order=$this->post[$focusorder];
			if(is_numeric($order)){
				$_ENV['doc']->order_focus($all_focus_did[$i],$order);
			}
		}
		$this->cache->removecache('indexcache');
		$this->header("admin_focus-focuslist");
	}

	/*id,view doc content and edit*/
	function doedit(){
		if(!isset($this->post['editsubmit'])){
			$did=isset($this->get[2])?$this->get[2]:'';
			if(!is_numeric($did)){
				$this->message($this->view->lang['docIdMustNum'],'BACK');
			}
			$focus=$_ENV['doc']->get_focus_content($did);
			$focus['time']=$this->date($focus['time']);
			$this->view->assign("focus",$focus);
			$this->view->display("admin_focus_content");
		}else{
			$did=isset($this->post['did'])?$this->post['did']:'';
			if(!is_numeric($did)){
				$this->message($this->view->lang['docIdMustNum'],'BACK');
			}
			$summary=string::hiconv($this->post['summary']);
			$image=string::hiconv($this->post['image']);
			$order=$this->post['displayorder'];
			if(is_numeric($order)&&$_ENV['doc']->save_focus_content($did,$summary,$image,$order)){
				$this->cache->removecache('indexcache');
				$this->message($this->view->lang['docEditSuccess'],"index.php?admin_focus-edit-$did");
			}else{
				$this->message($this->view->lang['docEditFail'],'BACK');
			}
		}
	}
	/*update imgage*/
	function doupdateimg(){
		@$did=$this->get[2];
		if(!is_numeric($did)){
			$this->message($this->view->lang['docIdMustNum'],'BACK');
		}
		$doc=$_ENV['doc']->get_doc($did);
		if(is_array($doc)){
			$img=$_ENV['doc']->setfocusimg(util::getfirstimg($doc['content']));
			if($img!=''){
				$doc=$_ENV['doc']->save_focus_img($did,$img);
			}
			$this->cache->removecache('indexcache');
			$this->header("admin_focus-focuslist");
		}else{
			$this->message($this->view->lang['docNoContentFail'],'BACK');
		}
	}
	
	/*doc number*/
	function donumset(){
		$this->view->display("admin_numset");
	}
}